package com.zhentao.controller;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.zhentao.domain.SysUserElectric;
import com.zhentao.domain.vo.Result;
import com.zhentao.service.SysUserElectricService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * @ClassName: SysUserElectricController
 * @Desrciption: Mr.chengfenzhan
 * @Author: 知安_程烽展
 * @Date: 2024/8/22 22:11
 */
@RestController
@RequestMapping("/sysuserelectric")
@Tag(name = "用户电卡管理")
public class SysUserElectricController {
    @Autowired
    private SysUserElectricService sysUserElectricService;
    @GetMapping("/getUserCard")
    @Operation(summary = "获取用户电卡")
    public Result getUserCard(@RequestHeader("Authorization") String token)
    {
        return sysUserElectricService.getUserCard(token);
    }
    //
    @PostMapping("/addCard")
    @Operation(summary = "添加电卡")
    public Result getCard(@RequestHeader("Authorization") String token, Integer str,Integer num,Integer juan) throws ParseException {
        return sysUserElectricService.addCard(token,str,num,juan);
    }
    @DeleteMapping("/removeById")
    @Operation(summary = "删除电卡")
    public Result removeById(@RequestParam("id") Integer id)
    {
        return sysUserElectricService.removeById(id)?Result.build(null,200,"删除成功"):Result.build(null,400,"删除失败");
    }

    @PutMapping("/status")
    @Operation(summary = "修改电卡状态")
    public Result status(@RequestParam("id") Integer id,@RequestParam("status") Integer status)
    {
        System.err.println(status);
        SysUserElectric sysUserElectric = new SysUserElectric();
        if(status==0)
        sysUserElectric.setStatus(3);
        else if(status==3) sysUserElectric.setStatus(0);
        sysUserElectric.setId(id);
        return sysUserElectricService.updateById(sysUserElectric)?Result.build(null,200,"修改成功"):Result.build(null,400,"修改失败");
    }
}
